package com.cskaoyan.controller;


import com.cskaoyan.bean.BaseData;
import com.cskaoyan.bean.BaseParam;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.user.*;
import com.cskaoyan.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户管理模块
 * 摘花请求:admin
 * 会员管理    收货地址    会员收藏    会员足迹    搜索历史    意见反馈
 */
@RestController
@RequestMapping("admin")
public class UserController {

    @Autowired
    UserService userService;

    @Autowired
    AddressService addressService;

    @Autowired
    CollectService collectService;

    @Autowired
    FeedbackService feedbackService;

    @Autowired
    FootprintService footprintService;

    @Autowired
    SearchHistorySevice searchHistorySevice;

    // 会员管理块
    @GetMapping("user/list")
    public BaseRespVo list(BaseParam param, String username, String mobile) {
        BaseData<User> data = userService.query(param, username, mobile);
        return BaseRespVo.ok(data);
    }

    @PostMapping("user/update")
    public BaseRespVo update(@RequestBody User user){
        userService.update(user);
        return BaseRespVo.ok(1);
    }

    /**
     * 查询条件:用户id
     *
     * @param id
     * @return 返回一条用户信息, 如果id不存在则返回一个null
     */
    @GetMapping("user/detail")
    public BaseRespVo detail(Integer id) {
        User data = userService.detail(id);
        return BaseRespVo.ok(data);
    }

    // 收货地址

    /**
     *
     * @param param
     * @param name
     * @param userId
     * @return
     */
    @GetMapping("address/list")
    public BaseRespVo address(BaseParam param, String name, Integer userId) {
        BaseData<Address> data = addressService.address(param, name, userId);
        return BaseRespVo.ok(data);
    }

    // 会员收藏

    /**
     *
     * @param param
     * @param userId
     * @param valueld
     * @return
     */
    @GetMapping("collect/list")
    public BaseRespVo collect(BaseParam param, Integer userId, Integer valueld) {
        BaseData<Collect> data = collectService.address(param,userId,valueld);
        return BaseRespVo.ok(data);
    }

    // 会员足迹

    /**
     *
     * @param param
     * @param userId
     * @param goodsId
     * @return
     */
    @GetMapping("footprint/list")
    public BaseRespVo footprint(BaseParam param, Integer userId, Integer goodsId) {
        BaseData<FootprintVo> data = footprintService.footprint(param, userId, goodsId);
        return BaseRespVo.ok(data);
    }

    // 搜索历史

    /**
     *
     * @param param
     * @param userId
     * @param keyword
     * @return
     */
    @GetMapping("history/list")
    public BaseRespVo history(BaseParam param,Integer userId, String keyword) {
        BaseData<SearchHistory> data = searchHistorySevice.history(param, userId, keyword);
        return BaseRespVo.ok();
    }

    // 意见反馈
    @GetMapping("feedback/list")
    public BaseRespVo feedback(BaseParam param ,String username, Integer id) {
        BaseData<FeedbackVo> data = feedbackService.feedback(param, username, id);
        return BaseRespVo.ok(data);
    }
}
